package com.zhledu.mapreduce.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.net.URI;

public class WordCountDriver {

	public static void main(String[] args) throws Exception {
		Configuration conf=new Configuration();
		FileSystem fs= FileSystem.get(new URI("hdfs://master:9000"),conf);
		Path outPath=new Path(args[1]);
		if(fs.exists(outPath)) {
			fs.delete(outPath,true);
		}
		
		Job job= Job.getInstance(conf,"word-count");
		//�ƶ����jar�����������
		job.setJarByClass(WordCountDriver.class);
		//ָ��Mapper,Reduce��
		job.setMapperClass(WordCountMapper.class);
		job.setReducerClass(WordCountReduce.class);
		//ָ��Maper���̵��������
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(LongWritable.class);
		//ָ��������������
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(LongWritable.class);
		
		FileInputFormat.addInputPath(job, new Path(args[0]));
		FileOutputFormat.setOutputPath(job, outPath);
		System.exit(job.waitForCompletion(true)?0:1);

	}

}
